#!/bin/bash

# 停止并禁用 slapd 服务
systemctl stop slapd.service 2>/dev/null
systemctl disable slapd.service 2>/dev/null

# 卸载所有 openldap 相关包
if command -v dnf >/dev/null 2>&1; then
    dnf remove -y $(rpm -qa | grep '^openldap') 2>/dev/null
elif command -v yum >/dev/null 2>&1; then
    yum remove -y $(rpm -qa | grep '^openldap') 2>/dev/null
elif command -v apt-get >/dev/null 2>&1; then
    apt-get remove --purge -y slapd ldap-utils 2>/dev/null
fi

# 验证
if rpm -qa 2>/dev/null | grep -q '^openldap'; then
    echo "[-] openldap 相关包仍然存在"
    exit 1
else
    echo "[+] LDAP 服务器相关包已卸载"
    exit 0
fi
